package com.xuecheng.teaching.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuecheng.teaching.model.dto.WorkDTO;
import com.xuecheng.teaching.model.vo.IWorkPageList;
import com.xuecheng.teaching.service.WorkService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/work")
public class WorkController {

    @Resource
    private WorkService workService;

    /**
     * 分页查询作业列表
     */
    @PostMapping("/list")
    public IWorkPageList queryWorkList(@RequestParam(defaultValue = "1") Integer pageNo,
                                       @RequestParam(defaultValue = "10") Integer pageSize,
                                       @RequestParam(required = false) String title) {
        Page<WorkDTO> page = new Page<>(pageNo, pageSize);
        return workService.queryWorkList(page, title);
    }

    /**
     * 新增作业
     */
    @PostMapping
    public Long addWork(@RequestBody WorkDTO workDTO) {
        return workService.addWork(workDTO);
    }

    /**
     * 修改作业
     */
    @PutMapping
    public Boolean updateWork(@RequestBody WorkDTO workDTO) {
        return workService.updateWork(workDTO);
    }

    /**
     * 删除作业
     */
    @DeleteMapping("/{workId}")
    public Boolean deleteWork(@PathVariable Long workId) {
        return workService.deleteWork(workId);
    }

    /**
     * 查询作业详情
     */
    @GetMapping("/{workId}")
    public WorkDTO getWorkById(@PathVariable Long workId) {
        return workService.getWorkById(workId);
    }
}